package org.mango.service.impl;

import org.mango.bean.Sort;
import org.mango.mapper.GridMapper;
import org.mango.mapper.SortMapper;
import org.mango.mapper.TagMapper;
import org.mango.service.SortService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by meigang on 17/10/14.
 */
@Service
@Transactional
public class SortServiceImpl implements SortService {
    @Autowired
    SortMapper mapper;
    @Autowired
    GridMapper gridMapper;
    @Autowired
    TagMapper tagMapper;

    @Override
    public List<Sort> list(Map<String, Object> map) {
        return mapper.selectAll(map);
    }

    @Override
    public void add(Sort sort) {
        mapper.insert(sort);
    }

    @Override
    public Sort getById(String id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public void update(Sort sort) {
        mapper.updateByPrimaryKey(sort);
    }

    @Override
    public void delete(String id) {
        mapper.deleteByPrimaryKey(id);
    }

    @Override
    public List<Sort> listAll(Map<String, Object> map) {
        return mapper.listAll(map);
    }

    @Override
    public int gridNum(String id) {
        return mapper.gridNum(id);
    }

    @Override
    public Map<String, Integer> numAll(Map<String, Object> inmap) {
        int sortCount = mapper.countAll(inmap);
        int gridCount = gridMapper.countAll(inmap);
        int tagCount = tagMapper.countAll(inmap);
        Map<String,Integer> map = new HashMap<String, Integer>();
        map.put("sort",sortCount);
        map.put("grid",gridCount);
        map.put("tag",tagCount);
        return map;
    }
}
